package org.example.compare.util;

import java.sql.Time;
import java.util.Date;

public class TimeUtil {
    private static final long DAY_SECOND = 60 * 60 * 24 * 1000;
    public static int dateCompareTime(Date start, Date end) {
        long startTime = start.getTime() % DAY_SECOND;
        long endTime = end.getTime() % DAY_SECOND;
        return Long.compare(startTime, endTime);
    }

    //start > end, return 1; start = end, return 0; start < end, return -1;
    public static int compareTime(Time start, Time end) {
        long startTime = start.getTime() % DAY_SECOND;
        long endTime = end.getTime() % DAY_SECOND;
        return Long.compare(startTime, endTime);
    }

    public static int betweenTime(Time start, Time end) {
        int startTime = (int) (start.getTime() % DAY_SECOND);
        int endTime = (int) (end.getTime() % DAY_SECOND);
        return (endTime - startTime) / 1000;
    }

    public static Time toTime(Date workTime) {
        return new Time(workTime.getHours(), workTime.getMinutes(), workTime.getSeconds());
    }

    public static long diffDay(Date start, Date end) {
        Date startDate = new Date(start.getYear(), start.getMonth(), start.getDate());
        Date endDate = new Date(end.getYear(), end.getMonth(), end.getDate());

        long diff = endDate.getTime() - startDate.getTime();
        return diff / DAY_SECOND;
    }
}
